package main

import (
	"demo_test/webservice_demo/controller"
	"github.com/julienschmidt/httprouter"
	"log"
	"net/http"
)

func RegisterHandlers() *httprouter.Router {
	router := httprouter.New()
	router.GET("/Hello", controller.Hello)
	router.POST("/user", controller.AddUser)
	return router
}

type MiddleWareHandler struct {
	router *httprouter.Router
}

func (m MiddleWareHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Printf("用户请求%s\n", r.RequestURI)
	m.router.ServeHTTP(w, r)
}

func NewMiddleWareHandler(router *httprouter.Router) http.Handler {
	return MiddleWareHandler{router: router}
}
